import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { OrderParams } from './interface/manage';

@Injectable({
  providedIn: 'root'
})
export class OrderManageService {

  constructor(private http: HttpClient) { }

  //查询订单列表
  getOrderList(object: OrderParams): Observable<any> {
    return this.http.put('/v1/order/query', { 
      timeRange: object.timeRange,
      userId: object.userId,
      page: object.page,
      pageSize: object.pageSize,
      orderStatusFlag: object.orderStatusFlag,
      collectionName: object.collectionName,
      issuer: object.issuer })
  }

  //取消订单
  cancelOrder(orderId, userId): Observable<any>{
    return this.http.get('/v1/order/cancel',{ params: {orderId: orderId, userId: userId}})
  }
  
  //新建订单
  applyCollection(userId, collection, subCollectionId): Observable<any> {
    return this.http.post('v1/assets/apply', {
      userId: userId,
      collectionIndex: collection,
      subCollectionIndex: subCollectionId
    })
  }

  //支付订单
  getQrCode(userid, orderid, paymenttype): Observable<any>{
    return this.http.post('/v1/payment/prepay', {orderId: orderid, userId: userid, paymentMethod:paymenttype})
  }

  //通知连接websocket
  buildWebsocket(id):Observable<any>{
    return this.http.post('/v1/payment/ws', {orderId: id})
  }
}
